<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>       
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="${_resources}/logo.png"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">                                            
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />  
<title>项目模板类型定义</title>
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
<link rel="stylesheet" href="${_resources}bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="${_resources}bootstrap/bootstrap-table.min.css" />
<script type="text/javascript" src="${_resources}jquery-ui/jquery-ui-1.10.4.custom.min.js"></script>
<link rel="stylesheet" href="${_resources}jquery-ui/jquery-ui-1.10.4.custom.min.css" />
<script type="text/javascript">
var projectTemplate;
var userId ="${userId}";
var userName ="${userName}";
var user_id = "${user_id}";
var menuId ="${menuId}";
function getTableData (status){
	var  random= Math.random();
	projectTemplate = $("#projectTemplate").bootstrapTable({
		url : '${_baseUrl}/KmProjectDocumentTemplateController/selectProjectTemplate?random='+random,
		pagination: true,
		pageList: [5, 10, 20, 50],
  		queryParams: queryParams,
        columns: [{
        	 field: 'checked',
        	 checkbox:true,
        	 formatter : function(value, row, index) {
        		  if(userId=="sysadmin"){
                        	return ;
               	 }else if(userId=="admin"){
               		 if(row.editerId=="sysadmin"){
               			return {disabled: true};
               		 }else{
               			return ; 
               		 }
               	 }else{ 
               		 if(row.userId !=null){
               			if(!((row.editer==userName) && row.userId ==user_id)){
    	                		return {
    	                            disabled: true
    	                        };
    	                	}else{
    	                		return;
    	                	}
               		 }else{
               			 if(!(row.editer==userName)){
     	                		return {
     	                            disabled: true
     	                        };
     	                	}else{
     	                		return;
     	                	}
               		 }
                   }
               }
         }, {
             field: 'editerId',
             title: 'editerId',
             visible:false,
             width: 5
         }, {
            field: 'id',
            title: 'id',
            visible:false,
            width: 5
        },{
            field: 'projectTemplateName',
            title: '项目模板类型名称',
            width: 100,
            formatter : function(value, row, index) {
            	var str="";
            		str +="<a onClick=\"checkFun('"+row.id+"');\"  title='"+value+"' class=\"late_on_temp\">"+value+"</a>";  
				return str;
			}
	       },{
	           field: 'projectTypeName',
	           title: '适用项目类型',
	           width: 100
	       },{
	           field: 'demandName',
	           title: '需求追踪模板名称',
	           width: 100,
	           formatter:function(value,row,index){
	        	   var isRead=false;
	          	   if(userId=="sysadmin"){
	          		  isRead=false;
				   	 }else if(userId=="admin"){
	               		 if(row.editerId=="sysadmin"){
	               			 isRead=true;
	                		 }else{
	                			 isRead=false;
	                		 }
	                }else{
				   		 if(row.userId !=null){
				   			if(!((row.editer==userName) && row.userId ==user_id)){
				   				isRead=true;
				            	}else{
				            		isRead=false;
				            	}
				   		 }else{
				   			 if(!(row.editer==userName)){
				   				isRead=true;
				             	}else{
				             		isRead=false;
				             	}
				   		 }
				       }
	            	if(value != null){
	            		return "<a onClick=\"resetDemendTraceModel('"+row.id+"',"+isRead+");\"  title='"+value+"' class=\"late_on_temp\">"+value+"</a>";	
	            	}else{
	            		return "--";
	            	}
            }
        },{
            field: 'createDate',
            title: '上传时间',
            width: 100
        },{
            field: 'editer',
            title: '上传人员',
            width: 100,
            formatter : function(value, row, index) {
            	var str=value;
            	if(value=='sysadmin'){
            		str="平台初始化";
            	}
				return str;
            }
        }]
    });
	function queryParams(params){
		return {
		    pageSize: params.limit,
		    pageNo: params.pn,
		    sort : params.sort,
		    order : params.order,
		    projectTemplateName:$("#docName").val()
	   }
	}
}
//回车
$(document).keyup(function(event){
	  if(event.keyCode == 13){
		  selectProMessage();
	  }
});

function selectProMessage(){
	projectTemplate.bootstrapTable('refresh',{url:'${_baseUrl}/KmProjectDocumentTemplateController/searchProTemplate'});
}

//点击项目模板列表中“需求追踪模板名称”进入修改文档追踪关系界面
function resetDemendTraceModel(id,isRead){
	var tit="";
	if(isRead){
		tit="查看";
	}else{
		tit="修改";
	}
	var isOk = 1;
	layerIndex =layer.open({
		  type: 2, 
		  title:tit+'需求追踪模板',
		  shade: 0.3, //遮罩透明度
		  area: ['850px', '380px'],
		  maxmin: true, //允许全屏最小化
	      anim: false, //0-6的动画形式，-1不开启
		  content: "${_baseUrl}/kmDemandTraceController/setBeforeDocument?templateId="+id+"&damendId=&random="+Math.random()+"&isRead="+isRead,
		});
	layer.full(layerIndex);
}

//判断登录人是否admin或sysadmin
function getLoginInfo(){
	 var path="${_baseUrl}/documentTemplateController/returnLoginInfo";
	 $.ajax({    
			type: "POST",    
			async: false,    
			url:path,     
			dataType:"text",    
			success: function (data) {   
				
			    if(data=="true"||data==true){
			    	getTableData (true);
			    }else{
			    	getTableData (false);
			    }
			}   
		}); 
	
}

function alterPro(){
	random= Math.random();
	var objects =  $("#projectTemplate").bootstrapTable('getSelections');
	var id ="";
	if(objects.length>1){
		layer.msg("只能修改一个模板",{time:1500});
		return;
	}else{
		for(var i =0;i<objects.length;i++){
			if(id.length>0){
				id+=","+objects[i].id;
			}else{
				id=objects[i].id;
			}
		}
		if(id.length==0){
			layer.msg("请先选择项目模板");
			return;
		}
		if(judgeIfAlter(id)){
			layerIndex =layer.open({
				  type: 2, 
				  title:'修改项目模板信息',
				  area: ['850px', '380px'],
				  fixed: false, //不固定
				  maxmin: true,
				  shim: true,
				  content: "${_baseUrl}/KmProjectDocumentTemplateController/showUpdateProjectDocumentTemplate?projectTemplateId="+id+"&random"+random,
				});
			/* $("#popIframe").empty();	
			$("#popDiv").dialog({
				title:'修改项目模板信息',
				autoOpen: true,
				modal: true,
				position:'top',
				height: 500,
				width: 800
			});	
			$("#popIframe").attr("width","100%");
			$("#popIframe").attr("height","95%");
			$("#popIframe").attr("src","${_baseUrl}/projectTemplateTypeController/returnAlter?projectTemplateId="+id+"&random"+random); */
		}else{
			layer.msg("不能修改他人模板");
			return;			
		}
		
	}
	
}
//判断是否可以修改
function judgeIfAlter(id){
	var result =false;
	var  random= Math.random();
	 var path="${_baseUrl}/KmProjectDocumentTemplateController/judgeIfAlter?random="+random;
	 $.ajax({    
		type: "POST",    
		async: false,    
		url:path,   
		data:{
			"id":id      
		},    
		dataType:"json",    
		success: function (data) {   
			if(data.code=='1'){
				result = true;
			}else{
				result =false;
			}
		}   
	}); 
	
	return result;
}



//判断当前人员是否为编写人
function judgeCurrentUse(name){
	var  userName = "${userName}";
	if(userName==name){
		return true;
	}else{
		return false;
	}
}

$(function(){	
	getLoginInfo();
	getMenuPath();
	
})
//删除项目模板类型
function deleteFun(){

	var objects =  $("#projectTemplate").bootstrapTable('getSelections');
	var id ="";
	for(var i =0;i<objects.length;i++){
		/* if(objects[i].editer=='sysadmin'){
			 layer.msg("初始化数据不可删除");
				return;
		  }*/
		if(id.length>0){
			id+=","+objects[i].id;
		}else{
			id=objects[i].id;
		}
	}
	if(id.length==0){
		layer.msg("请先选择项目文档模板");
		return;
	}
	 var path="${_baseUrl}/projectDocumentTemplateController/delProjectTemplate?rand="+Math.random();
	 $.ajax({    
		type: "POST",    
		async: false,    
		url:path,   
		data:{
			"id":id      
		},    
		dataType:"json",    
		success: function (data) {   
			layer.msg(data.message,{shift:5,time:1500});
			refreshTable();		
		}   
	}); 
}
//新增项目模板类型
function addFun(){
	var  random= Math.random();
	layerIndex =layer.open({
		  type: 2, 
		  title:'创建项目模板类型',
		  area: ['850px', '380px'],
		  fixed: false, //不固定
		  maxmin: true,
		  shim: true,
		  content: "${_baseUrl}/KmProjectDocumentTemplateController/addProjectTemplate?random="+random,
		  success: function(){
			  document.onkeydown = function (e) { // 回车提交表单
				    var theEvent = window.event || e;
				    var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
				    if (code == 13) {
				    	 $(this).trigger("click");
							return false;
				    }
				}
		  },
			
	});
}
//查看项目模板类型信息
function checkFun(id){
	var  random= Math.random();
	layerIndex =layer.open({
		  type: 2, 
		  title:'查看项目模板类型信息',
		  area: ['850px', '380px'],
		  fixed: false, //不固定
		  maxmin: true,
		  shim: true,
		  content: "${_baseUrl}/KmProjectDocumentTemplateController/checkProjectTemplate?id="+id+"&random="+random,
		});
	
}
//新建需求追踪关系
function addDemandTrace(){
	var objects =  $("#projectTemplate").bootstrapTable('getSelections');
	if(objects.length ==0){
		layerIndex =layer.open({
			  type: 2, 
			  title:'设置需求追踪模板',
			  area: ['850px', '380px'],
			  fixed: false, //不固定
			  maxmin: true,
			  shim: true,
			  content: "${_baseUrl}/kmDemandTraceController/showDemandTrace?rand="+Math.random()
			});
	}else if(objects.length > 1){
		layer.msg("只能选择一个项目模板");
		return false;
	}else{
		var did="";
		var isOk = 1;
		layerIndex =layer.open({
			  type: 2, 
			  title:'新建需求追踪',
			  area: ['850px', '380px'],
			  fixed: false, //不固定
			  maxmin: true,
			  shim: true,
			  content: "${_baseUrl}/kmDemandTraceController/showAddDemandTrace1?templateId="+objects[0].id+"&damendId="+did+"&random="+Math.random()+"&isOk="+isOk,
			});
	}
}
//新建需求追踪关系
function addDemandTrace1(templateId,did){
	var isOk = 1;
	layerIndex =layer.open({
		  type: 2, 
		  title:'新建需求追踪',
		  area: ['850px', '380px'],
		  fixed: false, //不固定
		  maxmin: true,
		  shim: true,
		  content: "${_baseUrl}/kmDemandTraceController/showAddDemandTrace1?templateId="+templateId+"&damendId="+did+"&random="+Math.random()+"&isOk="+isOk,
		});
}
//新建需求追踪关系
function addDemandTrace2(templateId,did){
	layerIndex =layer.open({
		  type: 2, 
		  title:'新建需求追踪',
		  area: ['850px', '380px'],
		  fixed: false, //不固定
		  maxmin: true,
		  shim: true,
		  content: "${_baseUrl}/kmDemandTraceController/showAddDemandTrace?templateId="+templateId+"&damendId="+did+"&random="+Math.random(),
		});
}


function showDemandTrace(id){
	random= Math.random();
	layerIndex =layer.open({
		  type: 2, 
		  title:'修改项目模板信息',
		  area: ['850px', '380px'],
		  fixed: false, //不固定
		  maxmin: true,
		  shim: true,
		  content: "${_baseUrl}/projectTemplateTypeController/returnAlter?projectTemplateId="+id+"&random"+random,
		});
}

/* 关闭弹出框 */
function closeWin(){
	//$("#popDiv").dialog('close');
	layer.close(layerIndex);
}

function refreshTable(){
	projectTemplate.bootstrapTable('refresh');
}

function getMenuPath(){
	var path = "${_baseUrl}/KmGroupDocumentTemplateController/getMenuPath";
	$.ajax({
		type: "POST",
		async: true,
		url:path,
		data:{
			"menuId": menuId
		},
		dataType:"json",
		success: function (data) {
			if(data.code == "1"){
				$("#menuPath").text("当前位置 ："+data.data);
			}else{
				$("#menuPath").text("当前位置 ：");
			}
		},
		error:function(data){
			layer.msg("系统错误,请联系管理员");
		}
	});
}

</script>
<style type="text/css">
.fixed-table-container{border:0px}
table{border:1px solid #ddd;margin-top: 7px!important;}
.fixed-table-header{height:0px}
</style>
</head>
<body>
<div class="submenu">
	<div  class="func_header">
		<span id="menuPath"></span>
	</div>
    <div class="func_bar">
    	<div class="search_container">
	        <div class="func_search">
	        	<div class="func_search_div"></div>
	            <input type="text" id="docName" name="docName" value="${searchValue}" placeholder="请输入关键词" />
	            <a class="search_btn" onclick="selectProMessage();" id="search" href="javascript:;"></a>
	        </div>
	    </div>
        <div class="btn_container">
         	<shiro:hasPermission name="kmDemandTraceController:showAddDemandTrace1">
                  <a class="blue_btn" id="settingRequirementsTrackingTemplate"  onclick="addDemandTrace();">设置需求追踪模板</a>
		     </shiro:hasPermission>
        	<shiro:hasPermission name="KmProjectDocumentTemplateController:addProjectTemplate">
		        <a class="blue_btn" href="javascript:;" onclick="addFun();">新增</a>
		     </shiro:hasPermission>
         	 <shiro:hasPermission name="KmProjectDocumentTemplateController:showUpdateProjectDocumentTemplate">
		        <a class="blue_btn" href="javascript:;" onclick="alterPro();">修改</a>
		     </shiro:hasPermission>
		     <shiro:hasPermission name="ProjectDocumentTemplateController:delProjectTemplate">
		        <a class="blue_btn" href="javascript:;" onclick="deleteFun();">删除</a>
		     </shiro:hasPermission>
        </div>
    </div>
    <div style="overflow: auto; width:98%;margin: auto;">
    	<table id="projectTemplate" class="table table-bordered table_inline"></table>
	</div>
</div>
</body>	
</html>